<script setup>
import { useUserStore } from '@/stores/user.js'
import { Message, User } from '@element-plus/icons-vue'
import { ref } from 'vue'
/* const userStore = useUserStore()
const visibleDrawer = ref(false)
defineOptions({
  name: "UserProfile"
})
const userInfo = ref({})
// 编辑用户信息
const editUserInfo = () => {
  visibleDrawer.value = true
}
userInfo.value = userStore.user
// 提交
const submitUserInfo = () => {
  userStore.editUser(userInfo.value)
  ElMessage.success('编辑成功')
  visibleDrawer.value = false
  userInfo.value = userStore.user
}*/
const userStore = useUserStore()

// 表单数据
const form = ref({
  username: 'admin', // 登录名称
  nickname: '', // 用户昵称
  email: '', // 用户邮箱
});

form.value = userStore.user

// 表单校验规则
const rules = {
  nickname: [
    { required: true, message: '请输入昵称', trigger: 'blur' },
    { min: 2, max: 10, message: '昵称长度在 2 到 10 个字符', trigger: 'blur' },
  ],
  email: [
    { required: true, message: '请输入邮箱', trigger: 'blur' },
    { type: 'email', message: '请输入正确的邮箱格式', trigger: 'blur' },
  ],
};

// 表单引用
const formRef = ref(null);

// 提交处理
const onSubmit = () => {
  formRef.value.validate(async (valid) => {
    if (valid) {
      await userStore.editUser(form.value)
      ElMessage.success('表单提交成功');
      form.value = userStore.user
    } else {
      ElMessage.error('表单填写有误');
    }
  });
};
</script>

<template>
  <page-container title="基本资料">
    <el-row>
      <el-col :span="12">
    <el-form :model="form" :rules="rules" ref="formRef" label-width="100px">
      <!-- 登录名称（禁用输入） -->
      <el-form-item label="登录名称">
        <el-input v-model="form.username" disabled placeholder="请输入登录名称"></el-input>
      </el-form-item>

      <!-- 用户昵称 -->
      <el-form-item label="用户昵称" prop="nickname">
        <el-input v-model="form.nickname" placeholder="请输入昵称"></el-input>
      </el-form-item>

      <!-- 用户邮箱 -->
      <el-form-item label="用户邮箱" prop="email">
        <el-input v-model="form.email" placeholder="请输入邮箱"></el-input>
      </el-form-item>

      <!-- 提交按钮 -->
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
      </el-form-item>
    </el-form>
      </el-col>
    </el-row>
  </page-container>


</template>

<style scoped>

</style>
